//
//  PetInformationTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/17.
//

#import "PetInformationTableViewCell.h"

@implementation PetInformationTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatView{
    self.backgroundColor=[UIColor whiteColor];
    
    UIView *topView=[UIView new];
    [self.contentView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(126*_mainHeight);
    }];
    
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"昵称";
    label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    label.textColor=rgba(66,66,66,1);
    
    UITextField *text=[UITextField new];
    [topView addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(topView.mas_centerX);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text.text=self.nameStr;
    text.textColor=rgba(45,45,45,1);
    text.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(32)];
    text.textAlignment=NSTextAlignmentRight;
    text.delegate=self;
    text.tag=1;
    text.placeholder=@"请填写宠物昵称";
    text.returnKeyType=UIReturnKeyDone;
    
    UIView *xianView=[UIView new];
    [self.contentView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
    
    
    UIView *topView2=[UIView new];
    [self.contentView addSubview:topView2];
    [topView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
        make.height.mas_equalTo(116*_mainHeight);
    }];
    
    UILabel *label2=[UILabel new];
    [topView2 addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    
    NSString *titleStr=[NSString stringWithFormat:@"*宠物类别"];
    NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
    NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"*"]];//匹配得到的下标
    NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"宠物类别"]];//匹配得到的下标
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(255,84,61,1) range:priceRange];
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange2];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(66,66,66,1) range:priceRange2];
    label2.attributedText=titleAttri;
    
    UITextField *text2=[UITextField new];
    [topView2 addSubview:text2];
    [text2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(text);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text2.text=self.typeStr;
    text2.textColor=rgba(45,45,45,1);
    text2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text2.textAlignment=NSTextAlignmentRight;
    text2.delegate=self;
    text2.tag=2;
    text2.placeholder=@"狗";
    text2.returnKeyType=UIReturnKeyDone;
    UIView *leftView2=[UIView new];
    [leftView2 setFrame:CGRectMake(0, 0, 60*_mainWidth, 60*_mainHeight)];
    UIImageView *phoneImageView2=[UIImageView new];
    [leftView2 addSubview:phoneImageView2];
    [phoneImageView2 setFrame:CGRectMake(60*_mainWidth-27*_mainWidth, (60*_mainHeight-14*_mainWidth)/2, 27*_mainWidth, 14*_mainWidth)];
    phoneImageView2.image=[UIImage imageNamed:@"xiangxiazhankai"];
    text2.rightView = leftView2;
    text2.enabled=NO;
    text2.rightViewMode =UITextFieldViewModeAlways;
    
    UIView *xianView2=[UIView new];
    [self.contentView addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView2.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView2.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView3=[UIView new];
    [self.contentView addSubview:topView3];
    [topView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView2.mas_bottom);
        make.height.mas_equalTo(116*_mainHeight);
    }];
    
    UILabel *label3=[UILabel new];
    [topView3 addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    
    NSString *titleStr2=[NSString stringWithFormat:@"*宠物体型"];
    NSMutableAttributedString *titleAttri2 =  [[NSMutableAttributedString alloc] initWithString:titleStr2];
    NSRange priceRange3 = [titleStr2 rangeOfString:[NSString stringWithFormat:@"*"]];//匹配得到的下标
    NSRange priceRange4 = [titleStr2 rangeOfString:[NSString stringWithFormat:@"宠物体型"]];//匹配得到的下标
    [titleAttri2 addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange3];
    [titleAttri2 addAttribute:NSForegroundColorAttributeName value:rgba(255,84,61,1) range:priceRange3];
    
    [titleAttri2 addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange4];
    [titleAttri2 addAttribute:NSForegroundColorAttributeName value:rgba(66,66,66,1) range:priceRange4];
    label3.attributedText=titleAttri2;
    
    UITextField *text3=[UITextField new];
    [topView3 addSubview:text3];
    [text3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(text);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text3.text=self.shapeStr;
    text3.textColor=rgba(45,45,45,1);
    text3.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text3.textAlignment=NSTextAlignmentRight;
    text3.delegate=self;
    text3.tag=3;
    text3.placeholder=@"大";
    text3.returnKeyType=UIReturnKeyDone;
    UIView *leftView3=[UIView new];
    [leftView3 setFrame:CGRectMake(0, 0, 60*_mainWidth, 60*_mainHeight)];
    UIImageView *phoneImageView3=[UIImageView new];
    [leftView3 addSubview:phoneImageView3];
    [phoneImageView3 setFrame:CGRectMake(60*_mainWidth-27*_mainWidth, (60*_mainHeight-14*_mainWidth)/2, 27*_mainWidth, 14*_mainWidth)];
    phoneImageView3.image=[UIImage imageNamed:@"xiangxiazhankai"];
    text3.rightView = leftView3;
    text3.enabled=NO;
    text3.rightViewMode =UITextFieldViewModeAlways;
    
    UIView *xianView3=[UIView new];
    [self.contentView addSubview:xianView3];
    [xianView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView3.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView3.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView4=[UIView new];
    [self.contentView addSubview:topView4];
    [topView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView3.mas_bottom);
        make.height.mas_equalTo(116*_mainHeight);
    }];
    
    UILabel *label4=[UILabel new];
    [topView4 addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    
    NSString *titleStr3=[NSString stringWithFormat:@"*宠物重量"];
    NSMutableAttributedString *titleAttri3 =  [[NSMutableAttributedString alloc] initWithString:titleStr3];
    NSRange priceRange5 = [titleStr3 rangeOfString:[NSString stringWithFormat:@"*"]];//匹配得到的下标
    NSRange priceRange6 = [titleStr3 rangeOfString:[NSString stringWithFormat:@"宠物重量"]];//匹配得到的下标
    [titleAttri3 addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange5];
    [titleAttri3 addAttribute:NSForegroundColorAttributeName value:rgba(255,84,61,1) range:priceRange5];
    [titleAttri3 addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)] range:priceRange6];
    [titleAttri3 addAttribute:NSForegroundColorAttributeName value:rgba(66,66,66,1) range:priceRange6];
    label4.attributedText=titleAttri3;
    
    UITextField *text4=[UITextField new];
    [topView4 addSubview:text4];
    [text4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(text);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text4.text=self.scaleStr;
    text4.textColor=rgba(45,45,45,1);
    text4.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text4.textAlignment=NSTextAlignmentRight;
    text4.delegate=self;
    text4.tag=4;
    text4.placeholder=@"2kg以内";
    text4.returnKeyType=UIReturnKeyDone;
    
    UIView *leftView4=[UIView new];
    [leftView4 setFrame:CGRectMake(0, 0, 60*_mainWidth, 60*_mainHeight)];
    UIImageView *phoneImageView4=[UIImageView new];
    [leftView4 addSubview:phoneImageView4];
    [phoneImageView4 setFrame:CGRectMake(60*_mainWidth-27*_mainWidth, (60*_mainHeight-14*_mainWidth)/2, 27*_mainWidth, 14*_mainWidth)];
    phoneImageView4.image=[UIImage imageNamed:@"xiangxiazhankai"];
    text4.rightView = leftView4;
    text4.enabled=NO;
    text4.rightViewMode =UITextFieldViewModeAlways;
    
    UIView *xianView4=[UIView new];
    [self.contentView addSubview:xianView4];
    [xianView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView4.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView4.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView5=[UIView new];
    [self.contentView addSubview:topView5];
    [topView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView4.mas_bottom);
        make.height.mas_equalTo(115*_mainHeight);
    }];
    
    UILabel *label5=[UILabel new];
    [topView5 addSubview:label5];
    [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    label5.text=@"宠物过往病例史";
    label5.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    label5.textColor=rgba(66,66,66,1);
    
    
    UIView *topView6=[UIView new];
    [self.contentView addSubview:topView6];
    [topView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(topView5.mas_bottom);
        make.height.mas_equalTo(188*_mainHeight);
    }];
    
    UIView *textView=[UIView new];
    [topView6 addSubview:textView];
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(41*_mainWidth);
        make.right.mas_equalTo(-40*_mainWidth);
        make.top.bottom.mas_equalTo(0);
    }];
    textView.layer.cornerRadius=25*_mainHeight;
    textView.backgroundColor=rgba(248,248,247,1);
    
    UITextView *text5=[UITextView new];
    [textView addSubview:text5];
    [text5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(33*_mainWidth);
        make.top.mas_equalTo(28*_mainHeight);
        make.bottom.mas_equalTo(-28*_mainHeight);
        make.right.mas_equalTo(-33*_mainWidth);
    }];
    text5.tag=5;
    text5.backgroundColor=rgba(248,248,247,1);
    text5.layer.masksToBounds=YES;
    text5.layer.cornerRadius=25*_mainHeight;
    if (self.caseStr==nil) {
        text5.text=@"请填写宠物过往病例史";
        text5.textColor=rgba(196,196,198,1);
    }else{
        text5.text=self.caseStr;
        text5.textColor=rgba(45,45,45,1);
    }
    text5.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text5.delegate=self;
    text5.returnKeyType=UIReturnKeyDone;
    
    UIView *topView7=[UIView new];
    [self.contentView addSubview:topView7];
    [topView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(topView6.mas_bottom);
        make.height.mas_equalTo(115*_mainHeight);
    }];
    
    UILabel *label6=[UILabel new];
    [topView7 addSubview:label6];
    [label6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    label6.text=@"宠物相关照片";
    label6.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    label6.textColor=rgba(66,66,66,1);
    
    UIView *topView8=[UIView new];
    [self.contentView addSubview:topView8];
    [topView8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(topView7.mas_bottom);
        make.height.mas_equalTo(152*_mainHeight);
    }];
    
    UIButton *leftBtn=[UIButton new];
    [topView8 addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(52*_mainWidth);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(152*_mainHeight);
    }];
    leftBtn.tag=1;
    leftBtn.layer.masksToBounds=YES;
    leftBtn.layer.cornerRadius=13;
    if (self.dogImage==nil) {
        [leftBtn setImage:[UIImage imageNamed:@"chongwuzhaopian"] forState:0];
    }else{
        [leftBtn setImage:self.dogImage forState:0];
    }
    [leftBtn addTarget:self action:@selector(selectSelectPictureBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *rightBtn=[UIButton new];
    [topView8 addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(leftBtn.mas_right).mas_equalTo(20*_mainWidth);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(152*_mainHeight);
    }];
    rightBtn.tag=2;
    rightBtn.layer.masksToBounds=YES;
    rightBtn.layer.cornerRadius=13;
    if (self.cradImage==nil) {
        [rightBtn setImage:[UIImage imageNamed:@"hegezhengming"] forState:0];
    }else{
        [rightBtn setImage:self.cradImage forState:0];
    }
    
    
    [rightBtn addTarget:self action:@selector(selectSelectPictureBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *topView9=[UIView new];
    [self.contentView addSubview:topView9];
    [topView9 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(topView8.mas_bottom);
    }];
    
    UIButton *deleteBtn=[UIButton new];
    [topView9 addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(170*_mainWidth);
        make.height.mas_equalTo(50*_mainHeight);
    }];
    [deleteBtn setTitle:@"清空当前信息" forState:0];
    [deleteBtn setTitleColor:rgba(144,149,165,1) forState:0];
    deleteBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    deleteBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    [deleteBtn addTarget:self action:@selector(selectEmptyBtn) forControlEvents:UIControlEventTouchUpInside];
}
-(void)creatBtnView{
    self.backgroundColor=[UIColor clearColor];
    
    UIButton *signInBtn=[UIButton new];
    [self.contentView addSubview:signInBtn];
    [signInBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(39*_mainWidth);
        make.width.mas_equalTo(_mainW-78*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(_mainHeight*87);
    }];
    [signInBtn setTitle:@"确定" forState:0];
    [signInBtn setTitleColor:[UIColor whiteColor] forState:0];
    signInBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    
    [signInBtn layoutIfNeeded];
    signInBtn.layer.masksToBounds=YES;
    signInBtn.layer.cornerRadius=87*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = signInBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [signInBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    signInBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    signInBtn.layer.shadowOffset = CGSizeMake(0,0);
    signInBtn.layer.shadowOpacity = 1;
    signInBtn.layer.shadowRadius = 4;
}
-(void)textViewDidBeginEditing:(UITextView *)textView{
    textView.textColor=rgba(45, 45, 45, 1);
    NSString *textStr=textView.text;
    if ([textStr isEqual:@"请填写宠物过往病例史"]) {
        textView.text=@"";
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    NSString *textStr=textView.text;
    if ([ZQTools charIsNil:textStr]) {
        textView.text=@"请填写宠物过往病例史";
        textView.textColor=rgba(248,248,247, 1);
    }else{
        if (self.delegate!=nil) {
            [self.delegate textViewdDidEnd:textView];
        }
    }
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.delegate!=nil) {
        [self.delegate textFiledDidEnd:textField];
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([text isEqualToString:@"\n"]){
        [textView resignFirstResponder];
        return NO;
    }
    return YES;

}
-(void)selectEmptyBtn{
    if (self.delegate!=nil) {
        [self.delegate selectEmpty];
    }
}

-(void)selectSelectPictureBtn:(UIButton *)btn{
    if (self.delegate!=nil) {
        [self.delegate selectSelectPicture:btn.tag];
    }
}

@end
